package com.fun.demo.fun.design;

import java.util.HashMap;
import java.util.Map;

public class Prototype {
}


interface Shapex extends Cloneable {
    void draw();
    Shapex clone();
}

class Rectangle implements Shapex {
    @Override
    public void draw() {
        System.out.println("Inside Rectangle::draw() method.");
    }

    @Override
    public Shapex clone() {
        Rectangle clone = null;
        try {
            clone = (Rectangle) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return clone;
    }
}

class Squarex implements Shapex {
    @Override
    public void draw() {
        System.out.println("Inside Squarex::draw() method.");
    }

    @Override
    public Shapex clone() {
        Squarex clone = null;
        try {
            clone = (Squarex) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return clone;
    }
}

class ShapexCache {
    private static Map<String, Shapex> ShapexMap = new HashMap<>();

    public static Shapex getShapex(String ShapexId) {
        Shapex cachedShapex = ShapexMap.get(ShapexId);
        return (Shapex) cachedShapex.clone();
    }

    static {
        Shapex rect = new Rectangle();
        ShapexMap.put(rect.getClass().getSimpleName(), rect);

        Shapex Squarex = new Squarex();
        ShapexMap.put(Squarex.getClass().getSimpleName(), Squarex);
    }
}

